package share.storage;

import java.util.Hashtable;
import share.storage.io.FileLoader;
import share.storage.io.basic.BasicFileLoader;
import share.storage.io.exchange.ExFileLoader;

public class LoaderFactory {
	private static Hashtable<String, Class<? extends FileLoader>> map;

	static{
		map = new Hashtable<String, Class<? extends FileLoader>>();
		map.put("default", BasicFileLoader.class);
		map.put("exchange", ExFileLoader.class);
	}

	public static FileLoader newLoaderByName(String loader) {
		Class<? extends FileLoader> loaderClass = map.get(loader);
		try {
			if (loaderClass != null)
				return loaderClass.newInstance();
			else {
				Object instance = Class.forName(loader).newInstance();
				if(instance instanceof FileLoader)
					return (FileLoader) instance;
			}
		} catch (Exception e) {
			return null;
		}
		return null;
	}
}
